using LiJ.Common.Extention;
using System.Collections.Generic;

namespace LiJ.Pay.WeiXin.Pay.Mos
{
	/// <summary>
	/// 查询退款响应实体
	/// </summary>
	public class WxPayGetRefundResp : WxPayBaseResp
	{
		/// <summary>   
		///    设备号 可空 String(32) 终端设备号
		/// </summary>  
		public string device_info
		{
			get;
			set;
		}

		/// <summary>   
		///    微信订单号 必填 String(32) 微信订单号
		/// </summary>  
		public string transaction_id
		{
			get;
			set;
		}

		/// <summary>   
		///    商户订单号 必填 String(32) 商户系统内部的订单号
		/// </summary>  
		public string out_trade_no
		{
			get;
			set;
		}

		/// <summary>   
		///    订单金额 必填 Int 订单总金额，单位为分，只能为整数，详见支付金额
		/// </summary>  
		public int total_fee
		{
			get;
			set;
		}

		/// <summary>   
		///    应结订单金额 可空 Int 应结订单金额=订单金额-非充值代金券金额，应结订单金额《=订单金额。
		/// </summary>  
		public int settlement_total_fee
		{
			get;
			set;
		}

		/// <summary>   
		///    货币种类 可空 String(8) 订单金额货币类型，符合ISO 4217标准的三位字母代码，默认人民币：CNY，其他值列表详见货币类型
		/// </summary>  
		public string fee_type
		{
			get;
			set;
		}

		/// <summary>   
		///    现金支付金额 必填 Int 现金支付金额，单位为分，只能为整数，详见支付金额
		/// </summary>  
		public int cash_fee
		{
			get;
			set;
		}

		/// <summary>   
		///    退款笔数 必填 Int 退款记录数
		/// </summary>  
		public int refund_count
		{
			get;
			set;
		}

		/// <summary>   
		///    退款资金来源 可空 String(30) REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款/基本账户，REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款
		/// </summary>  
		public string refund_account
		{
			get;
			set;
		}

		/// <summary>
		/// 退款记录信息
		/// </summary>
		public List<WxPayRefundItemMo> refund_items
		{
			get;
			set;
		}

		/// <summary>
		/// 格式化自身属性部分
		/// </summary>
		protected override void FormatPropertiesFromMsg()
		{
			this.device_info = base["device_info"];
			this.transaction_id = base["transaction_id"];
			this.out_trade_no = base["out_trade_no"];
			this.total_fee = base["total_fee"].ToInt32(0);
			this.settlement_total_fee = base["settlement_total_fee"].ToInt32(0);
			this.fee_type = base["fee_type"];
			this.cash_fee = base["cash_fee"].ToInt32(0);
			this.refund_account = base["refund_account"];
			this.refund_count = base["refund_count"].ToInt32(0);
			if (this.refund_count > 0)
			{
				List<WxPayRefundItemMo> refund_items = new List<WxPayRefundItemMo>(this.refund_count);
				for (int i = 0; i < this.refund_count; i++)
				{
					WxPayRefundItemMo wxPayRefundItemMo = new WxPayRefundItemMo();
					wxPayRefundItemMo.out_refund_no = base["out_refund_no_" + i];
					wxPayRefundItemMo.refund_id = base["refund_id_" + i];
					wxPayRefundItemMo.refund_channel = base["refund_channel_" + i];
					wxPayRefundItemMo.settlement_refund_fee = base["settlement_refund_fee_" + i].ToInt32(0);
					wxPayRefundItemMo.coupon_type = base["coupon_type_" + i];
					wxPayRefundItemMo.coupon_refund_fee = base["coupon_refund_fee_" + i].ToInt32(0);
					wxPayRefundItemMo.coupon_refund_count = base["coupon_refund_count_" + i].ToInt32(0);
					wxPayRefundItemMo.refund_status = base["refund_status_" + i];
					wxPayRefundItemMo.refund_recv_accout = base["refund_recv_accout_" + i];
					if (wxPayRefundItemMo.coupon_refund_count > 0)
					{
						List<WxPayRefundCouponItemMo> list = new List<WxPayRefundCouponItemMo>(wxPayRefundItemMo.coupon_refund_count);
						for (int j = 0; j < wxPayRefundItemMo.coupon_refund_count; j++)
						{
							WxPayRefundCouponItemMo wxPayRefundCouponItemMo = new WxPayRefundCouponItemMo();
							wxPayRefundCouponItemMo.coupon_refund_fee = base[string.Format("coupon_refund_fee_{0}_{1}", i, j)].ToInt32(0);
							wxPayRefundCouponItemMo.coupon_refund_id = base[string.Format("coupon_refund_id_{0}_{1}", i, j)];
							list.Add(wxPayRefundCouponItemMo);
						}
						wxPayRefundItemMo.coupons = list;
					}
				}
				this.refund_items = refund_items;
			}
		}
	}
}
